﻿using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace Shop.Web.Controllers
{
    public class LoginController : Controller
    {
        // GET: Login
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult DengLu(string CustName,string Pwd)
        {
            string Md5Pwd = MD5Jm.Md5jm(Pwd);
            Customer  customer = CustomerService.GetCustomer(CustName);
            if (customer != null)
            {
                if (customer.Pwd == Md5Pwd)
                {
                    FormsAuthentication.SetAuthCookie(CustName, true);
                    return Json(new { Success = true, Message = "登录成功" });
                }
                else
                {
                    return Json(new { Success = false, Message = "密码错误" });
                }

            }
            else
            {
                return Json(new { Success = false, Message = "用户名不存在" });
            }
        }


        public ActionResult ZhuCe()
        {
           return View();
        }

        public ActionResult Register(string CustName,string Pwd,string Phone ,string Sex)
        {
            string Md5Pwd = MD5Jm.Md5jm(Pwd);
            int a = CustomerService.AddCustomer(CustName,Md5Pwd,Phone, Sex);
            if (a > 0)
            {
                return Json(new { Success = true, Message = "注册成功" });
            }
            else
            {
                return Json(new { Success = false, Message = "注册失败" });
            }

        }

        public ActionResult Test()
        {

            string a = MD5Jm.Md5jm("15");
            return Content(a);
        }

    }
}